/**
 * 表单控件-单行文本输入框
 */
;( function( global, factory ) {
	"use strict";
	if ( typeof define === "function" && define.amd ) {
		define(['jquery', 'util/commonUtil', 'components/BaseElement', 'util/formElementManager', 'util/formRender', 'util/formSetting'], function(a, b, c, d, e, f){
			return factory(global, a, b, c, d, e, f);
		});
	} else {
		factory(global);
	}
} )( typeof window !== "undefined" ? window : this, function( window, $, commonUtil, BaseElement, formElementManager, formRender, formSetting ) {
	//console.log(typeof BaseElement);
	class FormInput extends BaseElement {
		constructor(domId){
			super({
				"typeId": "FormInput",
				"domId": domId,
				"show": {
					"glyphicon": "glyphicon-text-size", //glyphicon图标
					"label": "单行文本框" //拖拽控件显示名称
				}
			});
			//console.log('FormInput create.');
		}
		
		createDom() {
			if(typeof this.dom === 'undefined') {
				let html = '';
				html += '<div class="form-group">';
				html += ' <label class="control-label"><span class="label-name">单行文本框</span></label>';
				html += ' <div class="control-div">';
				html += '  <div class="if-input-group">';
				html += '   <input class="form-control" type="text">';
				html += '  </div>';
				html += '  <div class="other-msg">';
				//html += '  <p class="validate-msg"></p><p class="static-info"></p>';
				html += '  </div>';
				html += '</div></div>';
				this.dom = commonUtil.textTurnDOM(html);
				this.$dom = $(this.dom);
			}
			return this.dom;
		}
		
		inputDom () {
			return this.$dom.find("input.form-control");
		}
		
		dom4SetDefaultValue() {
			if(typeof this.defaultValueDom === 'undefined') {
				let thisGhost = this;
				this.defaultValueDom = commonUtil.textTurnDOM('<input type="text" class="form-control" id="formSetting-defaultValue">');
				//默认值输入项绑定事件
				this.defaultValueDom.addEventListener('input', function(){
					let val = $(this).val();
					thisGhost.setDefaultValue(val);
				});
			}
			if(this.defaultValue) {
				this.defaultValueDom.value = this.defaultValue;
			}
			return this.defaultValueDom;
		}
		
		/**
		getDefaultValue() {
			return this.defaultValue;
		}
		
		setDefaultValue(val) {
			this.defaultValue = val;
			this.$dom.attr("data-default-value", encodeURIComponent(val));
			this.$dom.find(".form-control").val(val);
		}
		
		clearDefaultValue() {
			this.defaultValue = undefined;
			this.$dom.removeAttr("data-default-value");
			this.$dom.find(".form-control").val("");
		}
		*/
		/**
		 * 更新/获取 控件前缀内容
		 * val为空时，删除前缀内容
		 */
		prefix(val) {
			return super.prefix(val);
		}
		
		/**
		 * 更新/获取 控件后缀内容
		 * val为空时，删除后缀内容
		 */
		suffix(val) {
			return super.suffix(val);
		}
		
		formSets() {
			//console.log(this.settingItems);
			if(typeof this.settingItems === 'undefined') {
				super.formSets();
				//console.log(this.settingItems);
				this.settingItems.push(formSetting.prefix);
				this.settingItems.push(formSetting.suffix);
				this.settingItems.push(formSetting.inputLength);
				
			}
			return this.settingItems;
		}
	}
	return FormInput;
} );